package com.hspedu.homework.homework2;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/4/18
 * @time 19:20
 */
public class BubbleSort {
    public static void main(String[] args) throws IOException {
        ArrayList<Integer> integers = new ArrayList<>();
        FileReader reader = new FileReader("D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\data.txt");
        BufferedReader bufferedReader = new BufferedReader(reader);
        try {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                // ... do something with line
                String[] strings = line.split(",");
                for (String string : strings) {
                    integers.add(Integer.parseInt(string));
                }
            }
        } catch (IOException e) {
            // ... handle IO exception
        }
        Integer[] nums = integers.toArray(new Integer[0]);
        long start = System.currentTimeMillis();
        for (int i = 1; i <= nums.length - 1; i++) {
            int temp;
            for (int j = 1; j <= nums.length - i; j++) {
                if (nums[j - 1] > nums[j]) {
                    temp = nums[j];
                    nums[j] = nums[j - 1];
                    nums[j - 1] = temp;
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        System.out.println(Arrays.toString(nums));
    }
}
